package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2024/3/28 10:11
 * @apiNote
 */

public class Test01997FirstDayBeenInAllRooms {

    public static void main(String[] args) {

    }


    public int firstDayBeenInAllRooms(int[] nextVisit) {
        int mod = 1000000007;
        int n = nextVisit.length;
        int[] dp = new int[n];
        dp[0] = 2;
        for (int i = 1; i < n; i++) {
            int to = nextVisit[i];
            dp[i] = 2 + dp[i-1];
            if(to != 0){
                dp[i] = (dp[i] -dp[to-1] + mod) % mod;
            }
            dp[i] = (dp[i] + dp[i-1]) % mod;
        }
        return dp[n-2];
    }
}
